/*  This file is part of CASpp.

    CASpp is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    CASpp is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with CASpp.  If not, see <http://www.gnu.org/licenses/>.

    Copyright 2014 Jérome LAURENS

    See https://code.google.com/p/idalgo/

*/

#include <boost/foreach.hpp>
#include "map.h"
#include <caspp/node.h>
#include <caspp/compare.h>
#include <boost/algorithm/string/join.hpp>

CASPP_NS_BEGIN

bool SmallNodeFirst::operator()(const NodeRef & x,const NodeRef & y) const {
    return x.get() != 0 && y.get() != 0 && isTrue(*x<*y);
}

const std::string Map::description() const {
    return "(...↦...)";
}

const std::string description(const Map &__x) {
    return __x.description();
}

const std::string Map::longDescription(const std::string & name
                            , const size_t depth
                , const std::string &prefix) const {
    std::vector< std::string > list;
    list.push_back("Map: (...");
    std::ostringstream s;
    size_t i = depth;
    while (i--) {
        s << prefix;
    }
    s << name << "[";
    std::string start = s.str();
    BOOST_FOREACH(value_type p, *this) {
        s.str(std::string());
        s << start << p.first->description() << "]↦" << p.second->description();
        list.push_back(s.str());
    }
    list.push_back("...)");
    return boost::algorithm::join(list,"\n");
}

const std::string longDescription(const Map &__x
                                  , const std::string & name
                                  , const size_t depth
                                  , const std::string &prefix) {
    return __x.longDescription(name, depth, prefix);
}

CASPP_NS_END
